//
//  SystemTable.m
//  OperationPro
//
//  Created by yaxue wang on 16/11/4.
//  Copyright © 2016年 展鸿科技. All rights reserved.
//

#import "SystemTable.h"
#import "SystemTableCell.h"
#import "SystemModel.h"
@implementation SystemTable
- (void)initView{
    [super initView];
    [self setShowNoDataNotice:@"暂无内容"];
    self.backgroundColor =BackColor;
    self.separatorStyle=UITableViewCellSeparatorStyleNone;
    self.showsVerticalScrollIndicator =NO;
    [self registerCell:[SystemTableCell class] withModel:[SystemModel class]];
    [self setDataWithUrl:@"message_showSystemNotify" andParam:nil];
    [self setTableActionType:CTableActionType_Both];
    [self loadData];
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
  return self.mainData.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    SystemModel *model = [self.mainData objectAtIndex:indexPath.row];
    CGSize labelsize = CGSizeZero;
    CGSize namesize = CGSizeZero;
    NSString *name =model.S_title;
    NSString *context =model.S_brief;
    
    
    if ([context isEqualToString:@""]) {
    }else
    {
        namesize=[name sizeWithFont:F(14) constrainedToSize:CGSizeMake(WindowWidth-66, 900)];
        labelsize = [context sizeWithFont:F(12) constrainedToSize:CGSizeMake(WindowWidth-66, 900)];
    }
    return MAX(labelsize.height+namesize.height+82 , 130);
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSString *cellID = [NSString stringWithFormat:@"Cell_%@", NSStringFromClass([SystemModel class])];
    SystemTableCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[SystemTableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    cell.selectionStyle=UITableViewCellSelectionStyleNone;

    SystemModel *model = [self.mainData objectAtIndex:indexPath.row];
    [cell setModel:model];
    
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];

}
@end
